//
//  InfoViewController.m
//  DialectShare
//
//  Created by timmy zhong on 3/20/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "InfoViewController.h"
#import "User.h"
#import "LoginViewController.h"
#import "CachedImage.h"

@interface InfoViewController ()
@property (nonatomic, retain) CachedImage *avatar;
@end

@implementation InfoViewController
@synthesize avatarContainer = _avatarContainer, name = _name, moto = _moto, dialctsCount = _dialctsCount, friendsCount = _friendsCount, fansCount = _fansCount, commentsCount = _commentsCount, favsCount = _favsCount, avatar = _avatar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    self.avatarContainer = nil;
    self.name = nil;
    self.moto = nil;
    self.dialctsCount = nil;
    self.friendsCount = nil;
    self.favsCount = nil;
    self.commentsCount = nil;
    self.fansCount = nil;
    self.avatar = nil;
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _avatar = [[CachedImage alloc] initWithFrame:self.avatarContainer.bounds];
    [self.avatarContainer addSubview:_avatar];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    User *current = [User current];
    if (current == nil) {
        
        LoginViewController *loginController = [[LoginViewController alloc] init];
        [self presentModalViewController:loginController animated:YES];
        [loginController release];
        
        return ;
    }
    NSString *path = [[NSBundle mainBundle] pathForResource:@"user_icon" ofType:@"png"];
    [self.avatar showImageForUrl:current.avatar defaultImage:path];
    self.name.text = current.name;
    self.moto.text = current.moto;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



@end
